<template>
	<view>
		<view>
			<view class="header">
				<view class="header-1">石材分类</view>
				<view class="header-2">
					<view class="header-2-1">分类</view>
					<view class="header-2-2">食材</view>
				</view>
				<view class="myimg">
					<view class="myimg-1">
						<image :src="require('@/static/@1/caipusousuo_slices/mengbanzu 2.png')"></image>

						<input type="text" class="uni-item">

					</view>
				</view>
			</view>
			<!-- 主页 -->
			<view class="main">
				<view class="aside">
					<!-- 第一种样式 -->
					<!-- <view :class="{'aside-item':true,actived:item._id==clickId}" v-for="item in rightData" :key="item._id" 
					 @click="test(item._id)">
						{{item.cat_name}}
					</view> -->
					<!-- 第二种样式 -->
					<view :class="item._id==clickId?'aside-item actived':'aside-item'" v-for="item in rightData" :key="item._id"
					 @click="test(item._id)">
						{{item.cat_name}}
					</view>
				</view>
				<view class="right">
					<view class="right-item" v-for="item in rightData" :key="item._id">
						<view class="right-item-1">{{item.cat_name}}</view>
						<view class="speci">
							<view class="right-item-2" v-for="option in item.children" :key="option.cat_pid">
								<view class="right-item-2-1">
									<image :src="option.cat_icon"></image>
									<text>{{option.cat_name}}</text>
								</view>
							</view>
						</view>
					</view>


				</view>


			</view>

		</view>
	</view>
</template>

<script>
	import {
		getAllCategoriesApi
	} from "@/apis/category.js"
	export default {
		data() {
			return {
				rightData: [],
				clickId:"60e079fd65150000ab002c32"
			};
		},
		created() {
			this.getAllCategories()
		},
		methods: {
			test(par){
				this.clickId=par
			},
			getAllCategories() {
				getAllCategoriesApi()
					.then((res) => {
						console.log("数据获取成功", res)
						this.rightData = res
					})
			}
		}
	}
</script>

<style lang="scss">
	.header {
		height: 352rpx;
		width: 100%;
		background-image: url("@/static/@1/caipusousuo_slices/ditu .png");
		overflow: hidden;
		color: white;

		// margin-bottom: 40rpx;
		.header-1 {
			font-size: 36rpx;
			margin-top: 120rpx;
			width: 100%;
			text-align: center;
			margin-bottom: 48rpx;
		}

		.header-2 {
			height: 48rpx;
			width: 358rpx;
			border-radius: 30rpx;
			margin: 0 auto;
			border: 3rpx solid white;
			display: flex;
			margin-bottom: 24rpx;

			.header-2-1 {
				height: 100%;
				width: 50%;
				background-color: white;
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 30rpx;
				color: rgb(241, 131, 38);
				line-height: 48rpx;
			}

			.header-2-2 {
				height: 100%;
				width: 50%;
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 30rpx;
				line-height: 48rpx;
			}

		}

		.myimg {
			margin-left: 26rpx;
			height: 60rpx;
			width: 692rpx;
			border-radius: 40rpx;
			background-color: white;
			display: flex;
			justify-content: center;
			align-items: center;

			.myimg-1 {
				width: 332rpx;
				height: 60rpx;
				display: flex;
				align-items: center;

				image {
					width: 32rpx;
					height: 32rpx;
				}

				.uni-item {
					height: 32rpx;
					width: 32rpx;
				}
			}
		}
	}

	.main {
		width: 100%;
		max-height: 100%;
		background-color: yellow;
		display: flex;

		.aside {
			width: 180rpx;
			background-color: white;
			border-right: 2rpx solid rgb(246, 246, 246);
			.aside-item {
				width: 180rpx;
				height: 136rpx;
				text-align: center;
				line-height: 136rpx;
				font-size: 24rpx;
				color: gray;
			}
			.actived {
				background-color: rgb(246, 246, 246);
				color: rgb(246, 142, 30);
			}
		}

		

		.right {
			// border: 1px solid blue;
			width: 570rpx;
			flex-grow: 1;
			background-color: white;
			padding: 14rpx 32rpx 0 20rpx;

			.right-item {
				// border: 1px solid red;

				.right-item-1 {
					font-size: 18rpx;
					color: gray;
				}

				.speci {
					display: grid;
					grid-template-columns: repeat(3,1fr);
					.right-item-2 {
						margin-left: 12rpx;
						display: flex;
						justify-content: space-between;
						align-items: center;
						flex-wrap: wrap;
                      
						.right-item-2-1 {
							display: flex;
							flex-direction: column;
                            
							image {
								width: 100rpx;
								height: 100rpx;
								margin-bottom: 12rpx;
							}

							text {
								font-size: 18rpx;
								margin-bottom: 20rpx;
								margin-left: 30rpx;
							}
						}
					}
				}

			}
		}
	}
</style>
